<head>
    <meta charset="utf-8" title="Student - TDC" />
    <link href="CSS/register.css" rel="stylesheet">
    <meta charset="utf-8" />
  

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="msvalidate.01" content="9F288B3B53D32225CE6A7">
    <link rel="SHORTCUT ICON" href="icon/Flavicon"> 
    <script src="JS/jquery-1.11.1.min.js" type="text/javascript"></script>
    <link href="CSS/anime.css" rel="stylesheet">
    <script src="JS/Maincontent.js" type="text/javascript"></script>
    <script src="JS/dialogLogin.js" type="text/javascript"></script>        
    <script src="JS/slidebaner.js" type="text/javascript"></script>         
    <link href="CSS/dialogLogin.css" rel="stylesheet">     
    <link href="CSS/body.css" rel="stylesheet">

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>

<?php
require_once './connection.php';

//include_once './phpmailler/class.phpmailer.php';
//include_once './phpmailler/class.smtp.php'; 
function check_email($email) {
    if (strlen($email) == 0)
        return FALSE;
    if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
        return TRUE;
    return FALSE;
}
?>
<?php
$sql = 'SELECT * from members';
$members = query($sql);
?>



<?php


if (isset($_POST['btnRegister'])) {
    $password = md5(addslashes($_POST['pass']));
    $verify_password = md5(addslashes($_POST['veri_pass']));
    $email = $_POST['email'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    if (!$_POST['pass'] || !$_POST['veri_pass'] || !$email || !$firstname || !$lastname) {
        print "Xin vui lòng nhập đầy đủ các thông tin. <a href='javascript:history.go(-1)'>Nhấp vào đây để quay trở lại</a>";
        exit;
    }
    if (check_email($email) == FALSE) {
        print "Email không hợp lệ. <a href='javascript:history.go(-1)'>Nhấp vào đây để quay trở lại</a>";
        exit;
    }
    if ($password != $verify_password) {
        print "Mật khẩu không giống nhau, bạn hãy nhập lại mật khẩu. <a href='javascript:history.go(-1)'>Nhấp vào đây để quay trở lại</a>";
        exit;
    }
    $them = 'INSERT INTO members (pass,firstName,lastName,email)
                 VALUES ("' . $password . '","' . $firstname . '","' . $lastname . '","' . $email . '")';
    mysql_query($them);
    echo "<script>alert('Đăng Ký Thành Công');</script>";
    print "Chào mừng '$firstname' đã tạo  được thành công. <a href='login.php'>Nhấp vào đây để đăng nhập</a>";


    if (!$mail->Send()) {
        echo "Loi";
    } else {
        echo "<script>alert('Đăng Ký Thành Công')</script>";
// Xoa may dong kia the nao ??, cái này nó bị hiển thị ra, sau này mình làm thì mình redriect qua trang khác rồi ko quan tâm . Với lại tui cũng ko biêt xóa :)) , thank nhé. Vào kiem tra xem co chua
    }
}
?>







<?php
session_start();
?>
<?php
if (isset($_POST['res'])) {
    header("location: register.php");
}
if (isset($_POST['ok'])) {
    $u = $p = "";
    if ($_POST['username'] == NULL) {
        echo "Please enter your username<br />";
    } else {
        $u = $_POST['username'];
    }
    if ($_POST['password'] == NULL) {
        echo "Please enter your password<br />";
    } else {
        $p = md5($_POST['password']);
    }
    if ($u && $p) {
        $conn = mysql_connect("localhost", "root", "") or die("can't connect this database");
        mysql_select_db("demo", $conn);
        $sql = "SELECT * FROM `members` WHERE `pass` = '" . $p . "' and `email` = '" . $u . "'";
        $query = mysql_query($sql);
        if (mysql_num_rows($query) <= 0) {

            echo "<script>alert('Username or password is not correct, please try again');</script>";
            echo "<script>location.reload(true)</script>";
            die();
        } else {
            echo 'Login Success';
            $row = mysql_fetch_array($query);

            $_SESSION['User_e'] = $row[email];
            $_SESSION['User_l'] = $row[admin];
            if ($_SESSION['User_l'] == 1) {

                header("location: index.php");
                echo "<script>alert('Chào mừng Admin đăng nhập thành công');</script>";
                exit();
            } else {
                header("location: members.php");
                exit();
            }
        }
    }
}
if (isset($_SESSION['User_e'])) {
    $dislay = 'none';
} else {
    $dislay = '';
}
if (isset($_SESSION['User_e'])) {
    $dislaymag = '';
} else {
    $dislaymag = 'none';
}
?>

</div>


<body>

<header class="header">
    <div class="float-header">               
        <div id="container-s" class="container-s" style="position: fixed; top: 0px; left: 0px;">
            <div class="container-f">                               
                <div class="logo">
                    <div style="float:left;margin:9px 10px 0 0;">
                        <a href="animw-web-project">                                                             
                            <img src="icon/icon-logo.png" width="85px" alt="Anime.VN"/>
                        </a>                               
                    </div>  
                    <div style="float:right;margin:9px 10px 0 0;display: <?php echo $dislay ?>">
                        <a href="#login-box" class="login-window button">Đăng nhập</a>
                        <div id="login-box" class="login">
                            <p class="login_title"> Đăng nhập</p>
                            <a href="#" class="close"><img src="icon/Close-icon.png" class="img-close" title="Close Window" alt="Close" /></a>
                            <form method="post" class="login-content" action="index.php">
                                <label class="username">
                                    <span>Tên hoặc email</span>
                                    <input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Username">
                                </label>
                                <label class="password">
                                    <span>Mật khẩu</span>
                                    <input id="password" name="password" value="" type="password" placeholder="Password">

                                </label>
                                <button class="button submit-button" type="submit" name="ok">Đăng nhập</button>
                                <button class="button submit-button" type="submit" name="res">Đăng Ký</button>
                                <p>
                                    <a class="forgot" href="#">Quên mật khẩu?</a>
                                </p>        
                            </form>
                        </div>
                    </div>
                    <div style="float:right;margin:9px 10px 0 0;display: <?php echo $dislaymag ?>">
                        <a href="logout.php" class="button">Thoát</a>


                    </div>
                    <div style="float:right;margin:9px 10px 0 0;display: <?php echo $dislaymag ?>">
                        <a href="manager_user.php" class="button">Quản Lý Thành Viên</a>

                    </div>
                </div>
            </div>
        </div>  
    </div> 
    <!-- NAV -->
    <div id="nav-place-container" style="margin-top: 47px; height: 50px; width: 100%; border-bottom-color: rgb(238, 238, 238); border-bottom-width: 1px; border-bottom-style: solid; background:#aaa;">
        <div style="width:1000px; margin:0 auto;">
            <div style="position: relative; ">
                <div class="nav-place">
                    <div style="float:left; width:800px; margin-top: -7px;">                    
                        <ul class="nav-place-menu" style="margin-left: -40px;">
                            <li>
                                <a href="#" title="HOME" data-type="list">
                                    Trang Chủ
                                </a>
                            </li>
                            <li>
                                <a href="#" title = "Anime">Anime</a>
                                <ul>
                                    <li>
                                        <a href="#" title="New" >
                                            Mới Cập Nhật
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#" title="Hot" >
                                            Đang Hot
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#" title="Most">
                                            Xem Nhiều Nhất
                                        </a>
                                    </li>

                                </ul>
                            </li>
                            <li>
                                <a href="#" title="Manga" >Manga</a>
                            </li>
                            <li>
                                <a href="#" title="Coslay" >Game</a>
                            </li>
                            <li>
                                <a href="#" title="Diễn Đàn">Diễn Đàn</a>
                            </li>
                            <li>
                                <a href="#" title="Shop">
                                    Shop                                     
                                </a>                                 
                                <ul>
                                    <li>
                                        <a href="#" title="Coslay" >
                                            Trang Phục Coslay
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#" title="Manga" >
                                            Truyện Tranh
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#" title="Event">
                                            Game
                                        </a>
                                    </li>

                                </ul>


                            </li>                                   
                            <li>
                                <a href="#" title="Contact">
                                    Liên Hệ
                                </a>
                            </li>

                            <li>
                                <a href="#" title="" data-type="QA">
                                    Hỏi Đáp
                                </a>
                            </li>

                        </ul>
                    </div>
                    <div style="float: right; margin-top: 4px;">
                        <a href="#" title="Mobile App "> Ứng Dụng</a>
                        <a href="#" title="Mobile App "> Giúp Đỡ</a>                          
                        <a style="float:left;border-left:0px; font-weight:normal;" onclick="return changeLanguage('vn')" rel="nofollow" href="/common/changelanguage?code=vn&amp;returnUrl=http%3A%2F%2Fwww.foody.vn%2F">
                            <img src="icon/english.png" height="16" alt="vn" style="float:left;margin-right:3px;margin-top:15px;"> EN

                        </a>
                    </div>
                </div>                       
            </div>
        </div>
    </div>
</header>            

<!-- END NAV -->

    <div id="layoutregister">
        <div id="title-register">Đăng Ký Tài Khoản</div>
        <div id="form-register">
            <form action="register.php" method="post" align="center">
                <table border="0" width="500" cellspacing="1" style="border-collapse: collapse; color: #00A69B;" bordercolor="#C0C0C0">
                    <tr>
                        <td>LastName : </td>
                        <td><input type="text" name="lastname" size="20" /></br</td>
                    </tr>
                    <tr>
                        <td>FirstName : </td>
                        <td><input type="text" name="firstname" size="20" /></td>
                    </tr>
                    <tr>
                        <td>Mật khẩu:</td>
                        <td><input type="password" name="pass" size="20" /></td>
                    </tr>
                    <tr>
                        <td>Xác nhận mật khẩu:</td>
                        <td><input type="password" name="veri_pass" size="20" /></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td><input type="text" name="email" size="20" /></td>
                    </tr>
                    <tr>
                        <td>
                            <label for="captcha">Captcha</label>
                        </td>
                        <td>
                            
                            <img src="random_image.php" id="captcha" /></br>
                            <input type="text" name="txtCaptcha" maxlength="10" size="10" />   <input type="button" id="reload" value="Reload" />
                        </td>

                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="btnRegister" value="Đăng ký tài khoản"></td>
                       
                    </tr>
                </table>
            </form>
             
        </div>
    </div>
<script>
		$(function() { // Handler for .ready() called.
			
			$('#reload').click(function(){				
				$('#captcha').attr('src', 'random_image.php?' + (new Date).getTime());
			});
		});
		</script>

</body>







